package com.kx.game.center.container;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 管理逻辑服玩家数量的容器
 */
public class PlayerContainer {

    private static volatile PlayerContainer LOGIC_PLAYER_CONTAINER;

    private AtomicInteger atomicInteger = new AtomicInteger(0);

    private PlayerContainer(){

    }

    public static PlayerContainer getInstance(){
        if (LOGIC_PLAYER_CONTAINER == null){
            synchronized (PlayerContainer.class){
                if (LOGIC_PLAYER_CONTAINER == null){
                    LOGIC_PLAYER_CONTAINER = new PlayerContainer();
                }
            }
        }
        return LOGIC_PLAYER_CONTAINER;
    }

    public void incrementAndGet(){
        atomicInteger.incrementAndGet();
    }

    public void decrementAndGet(){
        atomicInteger.decrementAndGet();
    }

    public int get(){
        return atomicInteger.get();
    }

}
